﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TrainingsApp.Model;

namespace TrainingsApp.IPADApp.Master {
    public partial class CourseInfoManager : PageBase {
        protected void Page_Load(object sender, EventArgs e) {
            DataBinds();
        }


        protected void DataBinds() {
            this.aspDataSource.DataSource = TrainingsApp.Logic.TS_CourseInfo_Logic.TS_CourseInfo_ListByPaging(10000, 1).TS_CourseInfo_List;
            this.aspDataSource.DataBind();
        }




        protected void aspDataSource_RowDeleted(object sender, DevExpress.Web.Data.ASPxDataDeletedEventArgs e) {
            e.ExceptionHandled = true;
        }

        protected void aspDataSource_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e) {


            int key = Convert.ToInt32(e.Keys["Idx"]);

            TrainingsApp.Logic.TS_CourseInfo_Logic.TS_CourseInfo_Delete(key);

            DataBinds();

        }

        protected void aspDataSource_RowInserted(object sender, DevExpress.Web.Data.ASPxDataInsertedEventArgs e) {
            e.ExceptionHandled = true;
        }

        protected void aspDataSource_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e) {


            string coursename = e.NewValues["CourseName"] == null ? string.Empty : e.NewValues["CourseName"].ToString();


            TS_CourseInfo_Entity courseInfo = new TS_CourseInfo_Entity();
            courseInfo.CourseName = coursename;


            TrainingsApp.Logic.TS_CourseInfo_Logic.TS_CourseInfo_Add(courseInfo);

            DataBinds();


        }

        protected void aspDataSource_RowUpdated(object sender, DevExpress.Web.Data.ASPxDataUpdatedEventArgs e) {
            e.ExceptionHandled = true;
        }

        protected void aspDataSource_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e) {

            int key = Convert.ToInt32(e.Keys["Idx"]);
            string coursename = e.NewValues["CourseName"] == null ? string.Empty : e.NewValues["CourseName"].ToString();


            TS_CourseInfo_Entity courseInfo = new TS_CourseInfo_Entity();
            courseInfo.CourseName = coursename;
            courseInfo.Idx = key;

            TrainingsApp.Logic.TS_CourseInfo_Logic.TS_CourseInfo_Update(courseInfo);

            DataBinds();
        }
    }
}